<div class="tutorial-bundle" data-metadata-json='{"difficulty": "medium"}' data-tip-sha1="9985625f836cd89917909546208bfa8ac2b5d738"><div class="front-matter" data-complete-code-text='import pytch
import random


class Bowl(pytch.Sprite):
    Costumes = ["bowl.png"]

    @pytch.when_green_flag_clicked
    def move_with_keys(self):
        self.go_to_xy(0, -145)

        while True:
            if pytch.key_pressed("a"):
                if self.x_position &gt;= -145:
                    self.change_x(-2)
            if pytch.key_pressed("d"):
                if self.x_position &lt;= 190:
                    self.change_x(2)


class Apple(pytch.Sprite):
    Costumes = ["apple.png"]

    @pytch.when_I_receive("drop-apple")
    def move_down_stage(self):
        drop_x = random.randint(-145, 190)
        self.go_to_xy(drop_x, 200)
        self.show()
        while self.y_position &gt; -140:
            self.change_y(-3)
            if self.touching(Bowl):
                self.hide()
                pytch.broadcast("award-point")


class ScoreKeeper(pytch.Sprite):
    Costumes = ["Dani.png"]

    @pytch.when_green_flag_clicked
    def initialise(self):
        self.go_to_xy(-215, -115)
        self.score = 0
        self.say(self.score)

    @pytch.when_I_receive("award-point")
    def award_point(self):
        self.score += 1
        self.say(self.score)

    @pytch.when_green_flag_clicked
    def drop_apples(self):
        while True:
            pytch.broadcast_and_wait("drop-apple")
' data-initial-code-text="import pytch
"><h1>Catch the apple!</h1><p>This tutorial will show you how to make a simple game in Pytch.  The
player will move a basket to try to catch apples which fall down the
stage.</p><p><img alt="Screenshot" src="screenshot-w240-darker-bg.png#img-center"/></p><p>We'll develop the game in stages, showing how knowledge of Scratch
helps with understanding how things work in Python.</p></div><div class="chapter-content"><h2>Add a <em>Sprite</em> for the player's bowl</h2><p>We'll start with the Bowl which the player controls.  Just like in
Scratch, we make a <em>Sprite</em>.  In Pytch, we create a Sprite by adding
code to our program.</p><p>You need to make the following change to your program.  Clicking on
the blue "<code>?</code>" will show some help about understanding the changes
you need to make.</p><div class="patch-container" data-code-as-of-commit="import pytch


class Bowl(pytch.Sprite):
" data-slug="add-empty-Bowl"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>1</pre></td><td class="linenum"><pre>1</pre></td><td><pre>import pytch</pre></td></tr></tbody><tbody class="diff-add" data-added-text="

class Bowl(pytch.Sprite):
"><tr><td class="linenum"></td><td class="linenum"><pre>2</pre></td><td><pre></pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>3</pre></td><td><pre></pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>4</pre></td><td><pre>class Bowl(pytch.Sprite):</pre></td></tr></tbody></table></div></div><p>You will get an error if you try to run this now — then click back to
this <em>Tutorial</em> tab.  The problem is that we haven't said anything at
all about the <em>Bowl</em>.  We'll do that now, by saying what the bowl
should look like.</p><h3>Add a costume for the Sprite</h3><p>Pytch sprites have <em>costumes</em> just like Scratch sprites do.  This
tutorial comes with the images you need — you can see them in the
<em>Images and sounds</em> tab, then come back here by choosing the
<em>Tutorial</em> tab.  To add a costume to our Pytch sprite, we just need to
write code saying which image to use.  A Sprite has a special variable
called <code>Costumes</code> which tells Pytch about that Sprite's costumes.</p><p>Because a Sprite can have more than one costume, we give Pytch a
<em>list</em> of the costumes we want to use, even if there's only one
costume in that list.  Python writes lists with square brackets, like
this:</p><pre><code>["red", "blue", "green"]
</code></pre><p>The costume we want to use is called <code>"bowl.png"</code>, so we make a list
with just that in it:</p><div class="patch-container" data-code-as-of-commit='import pytch


class Bowl(pytch.Sprite):
    Costumes = ["bowl.png"]
' data-slug="add-Bowl-costume"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>2</pre></td><td class="linenum"><pre>2</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>3</pre></td><td class="linenum"><pre>3</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>4</pre></td><td class="linenum"><pre>4</pre></td><td><pre>class Bowl(pytch.Sprite):</pre></td></tr></tbody><tbody class="diff-add" data-added-text='    Costumes = ["bowl.png"]
'><tr><td class="linenum"></td><td class="linenum"><pre>5</pre></td><td><pre>    Costumes = ["bowl.png"]</pre></td></tr></tbody></table></div></div><p>Now, if you click the green flag, you should see the player's bowl
appear in the middle of the stage.  Test that now!</p></div><div class="chapter-content"><h2>Start the bowl in the right place</h2><p>The player needs to be able to move the bowl.  We'll let them do this
with the keyboard, using the <code>a</code> and <code>d</code> keys.  In Scratch, we would
do this by adding a script to our Sprite, clicking the blocks
together.  In Pytch, we write code to do the same job.</p><p>The Pytch equivalent of adding a script is <em>defining a method</em> in our
Sprite.  Our method will start off by moving the bowl to the correct
place on the stage.  A Python method needs a name, which should
briefly describe what it does.  We'll use <code>move_with_keys</code> for our
method's name.</p><p>Pytch uses the same way of describing positions on the stage as
Scratch does, so we'll start off by making our method just move the
bowl to a sensible place at the bottom of the stage.</p><div class="patch-container" data-code-as-of-commit='import pytch


class Bowl(pytch.Sprite):
    Costumes = ["bowl.png"]

    def move_with_keys(self):
        self.go_to_xy(0, -145)
' data-slug="define-skeleton-move-with-keys"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>3</pre></td><td class="linenum"><pre>3</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>4</pre></td><td class="linenum"><pre>4</pre></td><td><pre>class Bowl(pytch.Sprite):</pre></td></tr><tr><td class="linenum"><pre>5</pre></td><td class="linenum"><pre>5</pre></td><td><pre>    Costumes = ["bowl.png"]</pre></td></tr></tbody><tbody class="diff-add" data-added-text="
    def move_with_keys(self):
        self.go_to_xy(0, -145)
"><tr><td class="linenum"></td><td class="linenum"><pre>6</pre></td><td><pre></pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>7</pre></td><td><pre>    def move_with_keys(self):</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>8</pre></td><td><pre>        self.go_to_xy(0, -145)</pre></td></tr></tbody></table></div></div><p>In Scratch, you give a block the information it needs by filling in
the ‘holes’ in the block:</p><pre><code class="language-scratch">go to x: [0] y: [-145]
</code></pre><p>In Python, you provide these extra pieces of information (called
“arguments”) in brackets “<code>()</code>” after the method name:</p><pre><code>self.go_to_xy(0, -145)
</code></pre><p>The "<code>self.</code>" part at the start means we want the Sprite to do
something.  The <code>x</code>-coordinate of <code>0</code> puts the bowl in the middle,
left-to-right.  I picked <code>-145</code> for the <code>y</code>-coordinate by trial and
error.</p><p>If you click the green flag now, our new code does not run.  This is because
what we've done so far is like making a script in Scratch with <em>no hat
block</em> on top.  In Scratch we would attach a <em>when green flag clicked</em>
hat block on top of our script.  In Pytch, we do something very
similar, by attaching a special marker to the top of the method:</p><div class="patch-container" data-code-as-of-commit='import pytch


class Bowl(pytch.Sprite):
    Costumes = ["bowl.png"]

    @pytch.when_green_flag_clicked
    def move_with_keys(self):
        self.go_to_xy(0, -145)
' data-slug="trigger-move-with-keys-on-green-flag"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>4</pre></td><td class="linenum"><pre>4</pre></td><td><pre>class Bowl(pytch.Sprite):</pre></td></tr><tr><td class="linenum"><pre>5</pre></td><td class="linenum"><pre>5</pre></td><td><pre>    Costumes = ["bowl.png"]</pre></td></tr><tr><td class="linenum"><pre>6</pre></td><td class="linenum"><pre>6</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-add" data-added-text="    @pytch.when_green_flag_clicked
"><tr><td class="linenum"></td><td class="linenum"><pre>7</pre></td><td><pre>    @pytch.when_green_flag_clicked</pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>7</pre></td><td class="linenum"><pre>8</pre></td><td><pre>    def move_with_keys(self):</pre></td></tr><tr><td class="linenum"><pre>8</pre></td><td class="linenum"><pre>9</pre></td><td><pre>        self.go_to_xy(0, -145)</pre></td></tr></tbody></table></div></div><p>Now if you click the green flag, the bowl should
move to its starting position at the bottom of the stage.</p></div><div class="chapter-content"><h2>Let the player move the bowl</h2><p>Now we're going to let the player move the bowl.  We'll start by
letting them move it to the right.  We'll keep checking whether the
player is pressing the <code>d</code> key, and if so, change the bowl's
<code>x</code>-coordinate.  In Scratch we would do this with a <em>forever</em> block.
Python has the <code>while True</code> statement to do the same job.</p><p>In Scratch, the blocks we want to run forever are <em>inside</em> the
<em>forever</em> block.  In Python, the code we want to run forever is
<em>indented</em> to the right.</p><p>Python's <em>if</em> statements work in the same way.  The code you want to
run only if the condition is true is indented to the right.</p><p>Putting this all together, we get this new code:</p><div class="patch-container" data-code-as-of-commit='import pytch


class Bowl(pytch.Sprite):
    Costumes = ["bowl.png"]

    @pytch.when_green_flag_clicked
    def move_with_keys(self):
        self.go_to_xy(0, -145)

        while True:
            if pytch.key_pressed("d"):
                self.change_x(2)
' data-slug="move-bowl-right"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>7</pre></td><td class="linenum"><pre>7</pre></td><td><pre>    @pytch.when_green_flag_clicked</pre></td></tr><tr><td class="linenum"><pre>8</pre></td><td class="linenum"><pre>8</pre></td><td><pre>    def move_with_keys(self):</pre></td></tr><tr><td class="linenum"><pre>9</pre></td><td class="linenum"><pre>9</pre></td><td><pre>        self.go_to_xy(0, -145)</pre></td></tr></tbody><tbody class="diff-add" data-added-text='
        while True:
            if pytch.key_pressed("d"):
                self.change_x(2)
'><tr><td class="linenum"></td><td class="linenum"><pre>10</pre></td><td><pre></pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>11</pre></td><td><pre>        while True:</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>12</pre></td><td><pre>            if pytch.key_pressed("d"):</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>13</pre></td><td><pre>                self.change_x(2)</pre></td></tr></tbody></table></div></div><p>If you try this, it should let you move the bowl right by holding down
the <code>d</code> key.  But!  You can move the bowl all the way off the stage.
We'll fix that next.</p><h3>Keep the bowl on the stage</h3><p>If the player is pressing <code>d</code>, we then need to check whether it's OK
to move the bowl right.  We do this be checking the bowl's
<code>x</code>-coordinate.  When the bowl is as far to the right as possible, the
<code>x</code>-coordinate is <code>190</code> — I found this value by trial and error in the
code below.  It's OK to move right as long as the <code>x</code>-coordinate is
less than or equal to 190.  We add a test for this, and only do the
<code>self.change_x(2)</code> if the test passes.</p><p>Maybe you can guess what the red line, marked with “<code>-</code>”, means — if
not, you can click on the blue “<code>?</code>” to get an explanation.</p><div class="patch-container" data-code-as-of-commit='import pytch


class Bowl(pytch.Sprite):
    Costumes = ["bowl.png"]

    @pytch.when_green_flag_clicked
    def move_with_keys(self):
        self.go_to_xy(0, -145)

        while True:
            if pytch.key_pressed("d"):
                if self.x_position &lt;= 190:
                    self.change_x(2)
' data-slug="clamp-bowl-at-right"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>10</pre></td><td class="linenum"><pre>10</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>11</pre></td><td class="linenum"><pre>11</pre></td><td><pre>        while True:</pre></td></tr><tr><td class="linenum"><pre>12</pre></td><td class="linenum"><pre>12</pre></td><td><pre>            if pytch.key_pressed("d"):</pre></td></tr></tbody><tbody class="diff-del"><tr><td class="linenum"><pre>13</pre></td><td class="linenum"></td><td><pre>                self.change_x(2)</pre></td></tr></tbody><tbody class="diff-add" data-added-text="                if self.x_position &lt;= 190:
                    self.change_x(2)
"><tr><td class="linenum"></td><td class="linenum"><pre>13</pre></td><td><pre>                if self.x_position &lt;= 190:</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>14</pre></td><td><pre>                    self.change_x(2)</pre></td></tr></tbody></table></div></div><p>Test this now — click the green flag, then check you
can still move right, but only as far as the edge of the stage.</p><h3>Let the player move left too</h3><p>The same idea will let the player move <em>left</em> as well.  We'll add code
to the same <code>while True</code> loop.  The differences for moving left
instead of right are:</p><ul>
<li>We check for the <code>"a"</code> key not the <code>"d"</code> key.</li>
<li>We check that the bowl is not too far left already, by checking that
  its <code>x</code>-coordinate is at least <code>-145</code>.  (I've left a bit of room at
  the very left for a score-keeper to stand — we'll come to the
  score-keeper later in the tutorial.)</li>
<li>We move by using a negative value for the amount the bowl should
  change its <code>x</code>-coordinate by.</li>
</ul><div class="patch-container" data-code-as-of-commit='import pytch


class Bowl(pytch.Sprite):
    Costumes = ["bowl.png"]

    @pytch.when_green_flag_clicked
    def move_with_keys(self):
        self.go_to_xy(0, -145)

        while True:
            if pytch.key_pressed("a"):
                if self.x_position &gt;= -145:
                    self.change_x(-2)
            if pytch.key_pressed("d"):
                if self.x_position &lt;= 190:
                    self.change_x(2)
' data-slug="move-clamp-bowl-left"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>9</pre></td><td class="linenum"><pre>9</pre></td><td><pre>        self.go_to_xy(0, -145)</pre></td></tr><tr><td class="linenum"><pre>10</pre></td><td class="linenum"><pre>10</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>11</pre></td><td class="linenum"><pre>11</pre></td><td><pre>        while True:</pre></td></tr></tbody><tbody class="diff-add" data-added-text='            if pytch.key_pressed("a"):
                if self.x_position &gt;= -145:
                    self.change_x(-2)
'><tr><td class="linenum"></td><td class="linenum"><pre>12</pre></td><td><pre>            if pytch.key_pressed("a"):</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>13</pre></td><td><pre>                if self.x_position &gt;= -145:</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>14</pre></td><td><pre>                    self.change_x(-2)</pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>12</pre></td><td class="linenum"><pre>15</pre></td><td><pre>            if pytch.key_pressed("d"):</pre></td></tr><tr><td class="linenum"><pre>13</pre></td><td class="linenum"><pre>16</pre></td><td><pre>                if self.x_position &lt;= 190:</pre></td></tr><tr><td class="linenum"><pre>14</pre></td><td class="linenum"><pre>17</pre></td><td><pre>                    self.change_x(2)</pre></td></tr></tbody></table></div></div></div><div class="chapter-content"><h2>Add a Sprite for the apple</h2><p>We now need something for the player to catch.  We'll create another
Sprite for this, and we'll start by adding a line of code to define
our new <em>Apple</em> Sprite:</p><div class="patch-container" data-code-as-of-commit='import pytch


class Bowl(pytch.Sprite):
    Costumes = ["bowl.png"]

    @pytch.when_green_flag_clicked
    def move_with_keys(self):
        self.go_to_xy(0, -145)

        while True:
            if pytch.key_pressed("a"):
                if self.x_position &gt;= -145:
                    self.change_x(-2)
            if pytch.key_pressed("d"):
                if self.x_position &lt;= 190:
                    self.change_x(2)


class Apple(pytch.Sprite):
' data-slug="add-empty-Apple-class"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>15</pre></td><td class="linenum"><pre>15</pre></td><td><pre>            if pytch.key_pressed("d"):</pre></td></tr><tr><td class="linenum"><pre>16</pre></td><td class="linenum"><pre>16</pre></td><td><pre>                if self.x_position &lt;= 190:</pre></td></tr><tr><td class="linenum"><pre>17</pre></td><td class="linenum"><pre>17</pre></td><td><pre>                    self.change_x(2)</pre></td></tr></tbody><tbody class="diff-add" data-added-text="

class Apple(pytch.Sprite):
"><tr><td class="linenum"></td><td class="linenum"><pre>18</pre></td><td><pre></pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>19</pre></td><td><pre></pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>20</pre></td><td><pre>class Apple(pytch.Sprite):</pre></td></tr></tbody></table></div></div><p>Before we can run this code, we need to put some code into the Apple
Sprite — we'll say what costume we want the Apple to have.  We're
taking the same steps here as what we did when we made the player's
bowl sprite.</p><div class="patch-container" data-code-as-of-commit='import pytch


class Bowl(pytch.Sprite):
    Costumes = ["bowl.png"]

    @pytch.when_green_flag_clicked
    def move_with_keys(self):
        self.go_to_xy(0, -145)

        while True:
            if pytch.key_pressed("a"):
                if self.x_position &gt;= -145:
                    self.change_x(-2)
            if pytch.key_pressed("d"):
                if self.x_position &lt;= 190:
                    self.change_x(2)


class Apple(pytch.Sprite):
    Costumes = ["apple.png"]
' data-slug="give-Apple-costume"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>18</pre></td><td class="linenum"><pre>18</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>19</pre></td><td class="linenum"><pre>19</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>20</pre></td><td class="linenum"><pre>20</pre></td><td><pre>class Apple(pytch.Sprite):</pre></td></tr></tbody><tbody class="diff-add" data-added-text='    Costumes = ["apple.png"]
'><tr><td class="linenum"></td><td class="linenum"><pre>21</pre></td><td><pre>    Costumes = ["apple.png"]</pre></td></tr></tbody></table></div></div><p>If you run the project now, an apple should appear in the middle of
the Stage.</p></div><div class="chapter-content"><h2>Make the apple fall down the stage</h2><p>To give the Apple its behaviour, we define a method — remember this is
like making a script in Scratch.  Because this is very similar to what
we did with the Bowl, we'll add this code all in one go.  We will:</p><ul>
<li>Say that we want this code to run when the green flag is clicked —
  this is like the 'hat block' in Scratch.</li>
<li>Give the method a short name to say what it does — we're using
  <code>move_down_stage</code>.  The code doesn't yet move the apple down the
  stage but it will!</li>
<li>Start the code off with a line which moves the Apple to a good
  starting point on the stage — I chose just off the top of the
  stage, and off-centre to the right a bit.</li>
</ul><div class="patch-container" data-code-as-of-commit='import pytch


class Bowl(pytch.Sprite):
    Costumes = ["bowl.png"]

    @pytch.when_green_flag_clicked
    def move_with_keys(self):
        self.go_to_xy(0, -145)

        while True:
            if pytch.key_pressed("a"):
                if self.x_position &gt;= -145:
                    self.change_x(-2)
            if pytch.key_pressed("d"):
                if self.x_position &lt;= 190:
                    self.change_x(2)


class Apple(pytch.Sprite):
    Costumes = ["apple.png"]

    @pytch.when_green_flag_clicked
    def move_down_stage(self):
        self.go_to_xy(100, 200)
' data-slug="define-skeleton-apple-move-down-screen"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>19</pre></td><td class="linenum"><pre>19</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>20</pre></td><td class="linenum"><pre>20</pre></td><td><pre>class Apple(pytch.Sprite):</pre></td></tr><tr><td class="linenum"><pre>21</pre></td><td class="linenum"><pre>21</pre></td><td><pre>    Costumes = ["apple.png"]</pre></td></tr></tbody><tbody class="diff-add" data-added-text="
    @pytch.when_green_flag_clicked
    def move_down_stage(self):
        self.go_to_xy(100, 200)
"><tr><td class="linenum"></td><td class="linenum"><pre>22</pre></td><td><pre></pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>23</pre></td><td><pre>    @pytch.when_green_flag_clicked</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>24</pre></td><td><pre>    def move_down_stage(self):</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>25</pre></td><td><pre>        self.go_to_xy(100, 200)</pre></td></tr></tbody></table></div></div><p>If you try this now (click green flag), you should just be able
to see the bottom of the apple at the top of the stage.</p><h3>Actually move down the stage</h3><p>What we want the apple to do is keep moving down, as long as it is
above the bottom of the stage.  In Scratch we could use a <code>repeat
until</code> block.  Python has a <code>while</code> statement instead.  This is very
like Scratch's <code>repeat until</code> block, but uses the test 'the other way
round' —</p><ul>
<li>Scratch's <code>repeat until</code> block keeps running the contained blocks,
  and <em>stops when the test is true</em>.</li>
<li>Python's <code>while</code> statement checks the test, and <em>runs the contained
  code while the test is true</em>.</li>
</ul><p>We want to test whether the apple's <code>y</code>-coordinate is higher than some
value near the bottom of the stage.  By trial and error, I found that
<code>-140</code> worked well for this.  We'll add this <code>while</code> loop to our
method:</p><div class="patch-container" data-code-as-of-commit='import pytch


class Bowl(pytch.Sprite):
    Costumes = ["bowl.png"]

    @pytch.when_green_flag_clicked
    def move_with_keys(self):
        self.go_to_xy(0, -145)

        while True:
            if pytch.key_pressed("a"):
                if self.x_position &gt;= -145:
                    self.change_x(-2)
            if pytch.key_pressed("d"):
                if self.x_position &lt;= 190:
                    self.change_x(2)


class Apple(pytch.Sprite):
    Costumes = ["apple.png"]

    @pytch.when_green_flag_clicked
    def move_down_stage(self):
        self.go_to_xy(100, 200)
        while self.y_position &gt; -140:
            self.change_y(-3)
' data-slug="make-apple-fall-down-screen"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>23</pre></td><td class="linenum"><pre>23</pre></td><td><pre>    @pytch.when_green_flag_clicked</pre></td></tr><tr><td class="linenum"><pre>24</pre></td><td class="linenum"><pre>24</pre></td><td><pre>    def move_down_stage(self):</pre></td></tr><tr><td class="linenum"><pre>25</pre></td><td class="linenum"><pre>25</pre></td><td><pre>        self.go_to_xy(100, 200)</pre></td></tr></tbody><tbody class="diff-add" data-added-text="        while self.y_position &gt; -140:
            self.change_y(-3)
"><tr><td class="linenum"></td><td class="linenum"><pre>26</pre></td><td><pre>        while self.y_position &gt; -140:</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>27</pre></td><td><pre>            self.change_y(-3)</pre></td></tr></tbody></table></div></div><p>We're changing the <code>y</code>-coordinate by the negative number <code>-3</code> to make
the apple move <em>down</em> the stage a small amount each time round the
<code>while</code> loop.</p><p>If you run this code, the apple should fall down the stage, and stop
at the bottom.</p><p>The <code>while</code> here might look different to when we used <code>while True</code> to
mean "forever", but it's really just different ways of using the same
thing.  When we want something to happen forever, the <code>True</code> in <code>while
True</code> acts as a test which always passes, so the indented code keeps
running again and again forever.</p></div><div class="chapter-content"><h2>Catch the apple in the bowl</h2><p>Finally, we want to let the player catch the apple.  Each time the
apple moves, it can check whether it's been caught.  This happens if
the apple is touching the player's bowl.  If it is, then we want to
hide the apple.  What we want to do is the Pytch equivalent of the
Scratch script</p><pre><code class="language-scratch">if &lt; touching (Bowl v)?&gt; then
hide
</code></pre><p>In Pytch, the code we need is:</p><div class="patch-container" data-code-as-of-commit='import pytch


class Bowl(pytch.Sprite):
    Costumes = ["bowl.png"]

    @pytch.when_green_flag_clicked
    def move_with_keys(self):
        self.go_to_xy(0, -145)

        while True:
            if pytch.key_pressed("a"):
                if self.x_position &gt;= -145:
                    self.change_x(-2)
            if pytch.key_pressed("d"):
                if self.x_position &lt;= 190:
                    self.change_x(2)


class Apple(pytch.Sprite):
    Costumes = ["apple.png"]

    @pytch.when_green_flag_clicked
    def move_down_stage(self):
        self.go_to_xy(100, 200)
        while self.y_position &gt; -140:
            self.change_y(-3)
            if self.touching(Bowl):
                self.hide()
' data-slug="hide-Apple-when-caught"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>25</pre></td><td class="linenum"><pre>25</pre></td><td><pre>        self.go_to_xy(100, 200)</pre></td></tr><tr><td class="linenum"><pre>26</pre></td><td class="linenum"><pre>26</pre></td><td><pre>        while self.y_position &gt; -140:</pre></td></tr><tr><td class="linenum"><pre>27</pre></td><td class="linenum"><pre>27</pre></td><td><pre>            self.change_y(-3)</pre></td></tr></tbody><tbody class="diff-add" data-added-text="            if self.touching(Bowl):
                self.hide()
"><tr><td class="linenum"></td><td class="linenum"><pre>28</pre></td><td><pre>            if self.touching(Bowl):</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>29</pre></td><td><pre>                self.hide()</pre></td></tr></tbody></table></div></div></div><div class="chapter-content"><h2>Add the score-keeper</h2><p>The next piece we want to work on is a score-keeper.  By now we know
how this works.  We define a new Sprite:</p><div class="patch-container" data-code-as-of-commit='import pytch


class Bowl(pytch.Sprite):
    Costumes = ["bowl.png"]

    @pytch.when_green_flag_clicked
    def move_with_keys(self):
        self.go_to_xy(0, -145)

        while True:
            if pytch.key_pressed("a"):
                if self.x_position &gt;= -145:
                    self.change_x(-2)
            if pytch.key_pressed("d"):
                if self.x_position &lt;= 190:
                    self.change_x(2)


class Apple(pytch.Sprite):
    Costumes = ["apple.png"]

    @pytch.when_green_flag_clicked
    def move_down_stage(self):
        self.go_to_xy(100, 200)
        while self.y_position &gt; -140:
            self.change_y(-3)
            if self.touching(Bowl):
                self.hide()


class ScoreKeeper(pytch.Sprite):
' data-slug="define-skeleton-ScoreKeeper-sprite"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>27</pre></td><td class="linenum"><pre>27</pre></td><td><pre>            self.change_y(-3)</pre></td></tr><tr><td class="linenum"><pre>28</pre></td><td class="linenum"><pre>28</pre></td><td><pre>            if self.touching(Bowl):</pre></td></tr><tr><td class="linenum"><pre>29</pre></td><td class="linenum"><pre>29</pre></td><td><pre>                self.hide()</pre></td></tr></tbody><tbody class="diff-add" data-added-text="

class ScoreKeeper(pytch.Sprite):
"><tr><td class="linenum"></td><td class="linenum"><pre>30</pre></td><td><pre></pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>31</pre></td><td><pre></pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>32</pre></td><td><pre>class ScoreKeeper(pytch.Sprite):</pre></td></tr></tbody></table></div></div><p>Give it a costume:</p><div class="patch-container" data-code-as-of-commit='import pytch


class Bowl(pytch.Sprite):
    Costumes = ["bowl.png"]

    @pytch.when_green_flag_clicked
    def move_with_keys(self):
        self.go_to_xy(0, -145)

        while True:
            if pytch.key_pressed("a"):
                if self.x_position &gt;= -145:
                    self.change_x(-2)
            if pytch.key_pressed("d"):
                if self.x_position &lt;= 190:
                    self.change_x(2)


class Apple(pytch.Sprite):
    Costumes = ["apple.png"]

    @pytch.when_green_flag_clicked
    def move_down_stage(self):
        self.go_to_xy(100, 200)
        while self.y_position &gt; -140:
            self.change_y(-3)
            if self.touching(Bowl):
                self.hide()


class ScoreKeeper(pytch.Sprite):
    Costumes = ["Dani.png"]
' data-slug="give-ScoreKeeper-costume"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>30</pre></td><td class="linenum"><pre>30</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>31</pre></td><td class="linenum"><pre>31</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>32</pre></td><td class="linenum"><pre>32</pre></td><td><pre>class ScoreKeeper(pytch.Sprite):</pre></td></tr></tbody><tbody class="diff-add" data-added-text='    Costumes = ["Dani.png"]
'><tr><td class="linenum"></td><td class="linenum"><pre>33</pre></td><td><pre>    Costumes = ["Dani.png"]</pre></td></tr></tbody></table></div></div><p>And make it move to a sensible place when the green flag is clicked.
I found these coordinates by trial and error, to put the score-keeper
in the bottom left corner of the stage.</p><div class="patch-container" data-code-as-of-commit='import pytch


class Bowl(pytch.Sprite):
    Costumes = ["bowl.png"]

    @pytch.when_green_flag_clicked
    def move_with_keys(self):
        self.go_to_xy(0, -145)

        while True:
            if pytch.key_pressed("a"):
                if self.x_position &gt;= -145:
                    self.change_x(-2)
            if pytch.key_pressed("d"):
                if self.x_position &lt;= 190:
                    self.change_x(2)


class Apple(pytch.Sprite):
    Costumes = ["apple.png"]

    @pytch.when_green_flag_clicked
    def move_down_stage(self):
        self.go_to_xy(100, 200)
        while self.y_position &gt; -140:
            self.change_y(-3)
            if self.touching(Bowl):
                self.hide()


class ScoreKeeper(pytch.Sprite):
    Costumes = ["Dani.png"]

    @pytch.when_green_flag_clicked
    def initialise(self):
        self.go_to_xy(-215, -115)
' data-slug="move-ScoreKeeper-to-right-place"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>31</pre></td><td class="linenum"><pre>31</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>32</pre></td><td class="linenum"><pre>32</pre></td><td><pre>class ScoreKeeper(pytch.Sprite):</pre></td></tr><tr><td class="linenum"><pre>33</pre></td><td class="linenum"><pre>33</pre></td><td><pre>    Costumes = ["Dani.png"]</pre></td></tr></tbody><tbody class="diff-add" data-added-text="
    @pytch.when_green_flag_clicked
    def initialise(self):
        self.go_to_xy(-215, -115)
"><tr><td class="linenum"></td><td class="linenum"><pre>34</pre></td><td><pre></pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>35</pre></td><td><pre>    @pytch.when_green_flag_clicked</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>36</pre></td><td><pre>    def initialise(self):</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>37</pre></td><td><pre>        self.go_to_xy(-215, -115)</pre></td></tr></tbody></table></div></div></div><div class="chapter-content"><h2>Start off with zero points</h2><p>When the player starts the game, they have no points.  We define a new
<em>variable</em> within the score-keeper.  This is just like when you make a
new <em>For this sprite only</em> variable in Scratch.  In Python, you can
just set a variable to a value, and this creates the variable.  We set
the starting value of a new <code>score</code> variable to zero:</p><div class="patch-container" data-code-as-of-commit='import pytch


class Bowl(pytch.Sprite):
    Costumes = ["bowl.png"]

    @pytch.when_green_flag_clicked
    def move_with_keys(self):
        self.go_to_xy(0, -145)

        while True:
            if pytch.key_pressed("a"):
                if self.x_position &gt;= -145:
                    self.change_x(-2)
            if pytch.key_pressed("d"):
                if self.x_position &lt;= 190:
                    self.change_x(2)


class Apple(pytch.Sprite):
    Costumes = ["apple.png"]

    @pytch.when_green_flag_clicked
    def move_down_stage(self):
        self.go_to_xy(100, 200)
        while self.y_position &gt; -140:
            self.change_y(-3)
            if self.touching(Bowl):
                self.hide()


class ScoreKeeper(pytch.Sprite):
    Costumes = ["Dani.png"]

    @pytch.when_green_flag_clicked
    def initialise(self):
        self.go_to_xy(-215, -115)
        self.score = 0
' data-slug="add-ScoreKeeper-score-attribute"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>35</pre></td><td class="linenum"><pre>35</pre></td><td><pre>    @pytch.when_green_flag_clicked</pre></td></tr><tr><td class="linenum"><pre>36</pre></td><td class="linenum"><pre>36</pre></td><td><pre>    def initialise(self):</pre></td></tr><tr><td class="linenum"><pre>37</pre></td><td class="linenum"><pre>37</pre></td><td><pre>        self.go_to_xy(-215, -115)</pre></td></tr></tbody><tbody class="diff-add" data-added-text="        self.score = 0
"><tr><td class="linenum"></td><td class="linenum"><pre>38</pre></td><td><pre>        self.score = 0</pre></td></tr></tbody></table></div></div><p>The “<code>self.</code>” is what makes this variable like Scratch’s <em>For this
sprite only</em>.</p><p>The job of the score-keeper is to announce the score, so we add a line
to say the value of the <code>score</code> variable:</p><div class="patch-container" data-code-as-of-commit='import pytch


class Bowl(pytch.Sprite):
    Costumes = ["bowl.png"]

    @pytch.when_green_flag_clicked
    def move_with_keys(self):
        self.go_to_xy(0, -145)

        while True:
            if pytch.key_pressed("a"):
                if self.x_position &gt;= -145:
                    self.change_x(-2)
            if pytch.key_pressed("d"):
                if self.x_position &lt;= 190:
                    self.change_x(2)


class Apple(pytch.Sprite):
    Costumes = ["apple.png"]

    @pytch.when_green_flag_clicked
    def move_down_stage(self):
        self.go_to_xy(100, 200)
        while self.y_position &gt; -140:
            self.change_y(-3)
            if self.touching(Bowl):
                self.hide()


class ScoreKeeper(pytch.Sprite):
    Costumes = ["Dani.png"]

    @pytch.when_green_flag_clicked
    def initialise(self):
        self.go_to_xy(-215, -115)
        self.score = 0
        self.say(self.score)
' data-slug="announce-starting-score"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>36</pre></td><td class="linenum"><pre>36</pre></td><td><pre>    def initialise(self):</pre></td></tr><tr><td class="linenum"><pre>37</pre></td><td class="linenum"><pre>37</pre></td><td><pre>        self.go_to_xy(-215, -115)</pre></td></tr><tr><td class="linenum"><pre>38</pre></td><td class="linenum"><pre>38</pre></td><td><pre>        self.score = 0</pre></td></tr></tbody><tbody class="diff-add" data-added-text="        self.say(self.score)
"><tr><td class="linenum"></td><td class="linenum"><pre>39</pre></td><td><pre>        self.say(self.score)</pre></td></tr></tbody></table></div></div><p>If you run this now, the score-keeper should say "<code>0</code>".</p></div><div class="chapter-content"><h2>Give a point for catching an apple</h2><p>The player can catch the apple in the bowl, but the score stays as
zero.  We will fix this next.</p><p>We'll define another method in the <code>ScoreKeeper</code> sprite.  That
method's job is to give the player a point and announce the new score.
A good short name for this job is <code>award_point</code>, so we define a method
with this name.  The first piece of code in our new method will
increase the <code>score</code> variable by <code>1</code>:</p><div class="patch-container" data-code-as-of-commit='import pytch


class Bowl(pytch.Sprite):
    Costumes = ["bowl.png"]

    @pytch.when_green_flag_clicked
    def move_with_keys(self):
        self.go_to_xy(0, -145)

        while True:
            if pytch.key_pressed("a"):
                if self.x_position &gt;= -145:
                    self.change_x(-2)
            if pytch.key_pressed("d"):
                if self.x_position &lt;= 190:
                    self.change_x(2)


class Apple(pytch.Sprite):
    Costumes = ["apple.png"]

    @pytch.when_green_flag_clicked
    def move_down_stage(self):
        self.go_to_xy(100, 200)
        while self.y_position &gt; -140:
            self.change_y(-3)
            if self.touching(Bowl):
                self.hide()


class ScoreKeeper(pytch.Sprite):
    Costumes = ["Dani.png"]

    @pytch.when_green_flag_clicked
    def initialise(self):
        self.go_to_xy(-215, -115)
        self.score = 0
        self.say(self.score)

    def award_point(self):
        self.score += 1
' data-slug="define-skeleton-award-point"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>37</pre></td><td class="linenum"><pre>37</pre></td><td><pre>        self.go_to_xy(-215, -115)</pre></td></tr><tr><td class="linenum"><pre>38</pre></td><td class="linenum"><pre>38</pre></td><td><pre>        self.score = 0</pre></td></tr><tr><td class="linenum"><pre>39</pre></td><td class="linenum"><pre>39</pre></td><td><pre>        self.say(self.score)</pre></td></tr></tbody><tbody class="diff-add" data-added-text="
    def award_point(self):
        self.score += 1
"><tr><td class="linenum"></td><td class="linenum"><pre>40</pre></td><td><pre></pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>41</pre></td><td><pre>    def award_point(self):</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>42</pre></td><td><pre>        self.score += 1</pre></td></tr></tbody></table></div></div><p>The <code>+=</code> is like Scratch’s <code>change (score) by (1)</code>.</p><p>And then we need to change what the score-keeper is saying to be the
new value of the <code>score</code> variable:</p><div class="patch-container" data-code-as-of-commit='import pytch


class Bowl(pytch.Sprite):
    Costumes = ["bowl.png"]

    @pytch.when_green_flag_clicked
    def move_with_keys(self):
        self.go_to_xy(0, -145)

        while True:
            if pytch.key_pressed("a"):
                if self.x_position &gt;= -145:
                    self.change_x(-2)
            if pytch.key_pressed("d"):
                if self.x_position &lt;= 190:
                    self.change_x(2)


class Apple(pytch.Sprite):
    Costumes = ["apple.png"]

    @pytch.when_green_flag_clicked
    def move_down_stage(self):
        self.go_to_xy(100, 200)
        while self.y_position &gt; -140:
            self.change_y(-3)
            if self.touching(Bowl):
                self.hide()


class ScoreKeeper(pytch.Sprite):
    Costumes = ["Dani.png"]

    @pytch.when_green_flag_clicked
    def initialise(self):
        self.go_to_xy(-215, -115)
        self.score = 0
        self.say(self.score)

    def award_point(self):
        self.score += 1
        self.say(self.score)
' data-slug="announce-updated-score"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>40</pre></td><td class="linenum"><pre>40</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>41</pre></td><td class="linenum"><pre>41</pre></td><td><pre>    def award_point(self):</pre></td></tr><tr><td class="linenum"><pre>42</pre></td><td class="linenum"><pre>42</pre></td><td><pre>        self.score += 1</pre></td></tr></tbody><tbody class="diff-add" data-added-text="        self.say(self.score)
"><tr><td class="linenum"></td><td class="linenum"><pre>43</pre></td><td><pre>        self.say(self.score)</pre></td></tr></tbody></table></div></div><p>Our code is correct, but we haven't said when to run it.  We want to
run this method whenever the apple lands in the bowl.  In our code,
it's the Apple's job to check whether it's landed in the bowl.  So,
just like in Scratch, we're going to make the Apple <em>broadcast a
message</em> when it knows that it's landed in the bowl.  We'll tell Pytch
to run our score-keeper's <code>award_point</code> method when it <em>receives</em> that
message.</p><p>Just like in Scratch, we have to choose a good message.  In Pytch, a
message can be any string — we'll use <code>"award-point"</code>.</p><p>This is just like in Scratch, where we would use a <code>broadcast</code> block:</p><pre><code class="language-scratch">broadcast (award-point v)
</code></pre><p>and a <code>when I receive</code> hat-block:</p><pre><code class="language-scratch">when I receive [award-point v]
</code></pre><p>And just like in Scratch, we have to choose a good message.  In Pytch,
a message can be any string — we'll use <code>"award-point"</code>.</p><p>First we tell Pytch to run <code>award_point</code> whenever the score-keeper
receives the message <code>"award-point"</code>:</p><div class="patch-container" data-code-as-of-commit='import pytch


class Bowl(pytch.Sprite):
    Costumes = ["bowl.png"]

    @pytch.when_green_flag_clicked
    def move_with_keys(self):
        self.go_to_xy(0, -145)

        while True:
            if pytch.key_pressed("a"):
                if self.x_position &gt;= -145:
                    self.change_x(-2)
            if pytch.key_pressed("d"):
                if self.x_position &lt;= 190:
                    self.change_x(2)


class Apple(pytch.Sprite):
    Costumes = ["apple.png"]

    @pytch.when_green_flag_clicked
    def move_down_stage(self):
        self.go_to_xy(100, 200)
        while self.y_position &gt; -140:
            self.change_y(-3)
            if self.touching(Bowl):
                self.hide()


class ScoreKeeper(pytch.Sprite):
    Costumes = ["Dani.png"]

    @pytch.when_green_flag_clicked
    def initialise(self):
        self.go_to_xy(-215, -115)
        self.score = 0
        self.say(self.score)

    @pytch.when_I_receive("award-point")
    def award_point(self):
        self.score += 1
        self.say(self.score)
' data-slug="trigger-award-point-on-message"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>38</pre></td><td class="linenum"><pre>38</pre></td><td><pre>        self.score = 0</pre></td></tr><tr><td class="linenum"><pre>39</pre></td><td class="linenum"><pre>39</pre></td><td><pre>        self.say(self.score)</pre></td></tr><tr><td class="linenum"><pre>40</pre></td><td class="linenum"><pre>40</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-add" data-added-text='    @pytch.when_I_receive("award-point")
'><tr><td class="linenum"></td><td class="linenum"><pre>41</pre></td><td><pre>    @pytch.when_I_receive("award-point")</pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>41</pre></td><td class="linenum"><pre>42</pre></td><td><pre>    def award_point(self):</pre></td></tr><tr><td class="linenum"><pre>42</pre></td><td class="linenum"><pre>43</pre></td><td><pre>        self.score += 1</pre></td></tr><tr><td class="linenum"><pre>43</pre></td><td class="linenum"><pre>44</pre></td><td><pre>        self.say(self.score)</pre></td></tr></tbody></table></div></div><p>And then we make the apple broadcast this message when it's caught.</p><p>This change needs to be made inside your <code>Apple</code> sprite:</p><div class="patch-container" data-code-as-of-commit='import pytch


class Bowl(pytch.Sprite):
    Costumes = ["bowl.png"]

    @pytch.when_green_flag_clicked
    def move_with_keys(self):
        self.go_to_xy(0, -145)

        while True:
            if pytch.key_pressed("a"):
                if self.x_position &gt;= -145:
                    self.change_x(-2)
            if pytch.key_pressed("d"):
                if self.x_position &lt;= 190:
                    self.change_x(2)


class Apple(pytch.Sprite):
    Costumes = ["apple.png"]

    @pytch.when_green_flag_clicked
    def move_down_stage(self):
        self.go_to_xy(100, 200)
        while self.y_position &gt; -140:
            self.change_y(-3)
            if self.touching(Bowl):
                self.hide()
                pytch.broadcast("award-point")


class ScoreKeeper(pytch.Sprite):
    Costumes = ["Dani.png"]

    @pytch.when_green_flag_clicked
    def initialise(self):
        self.go_to_xy(-215, -115)
        self.score = 0
        self.say(self.score)

    @pytch.when_I_receive("award-point")
    def award_point(self):
        self.score += 1
        self.say(self.score)
' data-slug="broadcast-when-apple-caught"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>27</pre></td><td class="linenum"><pre>27</pre></td><td><pre>            self.change_y(-3)</pre></td></tr><tr><td class="linenum"><pre>28</pre></td><td class="linenum"><pre>28</pre></td><td><pre>            if self.touching(Bowl):</pre></td></tr><tr><td class="linenum"><pre>29</pre></td><td class="linenum"><pre>29</pre></td><td><pre>                self.hide()</pre></td></tr></tbody><tbody class="diff-add" data-added-text='                pytch.broadcast("award-point")
'><tr><td class="linenum"></td><td class="linenum"><pre>30</pre></td><td><pre>                pytch.broadcast("award-point")</pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>30</pre></td><td class="linenum"><pre>31</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>31</pre></td><td class="linenum"><pre>32</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>32</pre></td><td class="linenum"><pre>33</pre></td><td><pre>class ScoreKeeper(pytch.Sprite):</pre></td></tr></tbody></table></div></div><p>If you try this now, you should be able to get your score from zero to
one by catching the apple.</p></div><div class="chapter-content"><h2>Drop the apple from a random place</h2><p>So far the game drops the apple in the same place every time you play.
This makes the game far too easy.  We want to make the apple drop in a
random place each time.</p><p>To do this, we will use some code which other people have already
written.  The name for a collection of Python code ready for use in
other programs is <em>module</em>.  A module for making random choices comes
with Python — this module is called <code>random</code>.  We say we want to use
the <code>random</code> module in our program by <em>importing</em> it:</p><div class="patch-container" data-code-as-of-commit='import pytch
import random


class Bowl(pytch.Sprite):
    Costumes = ["bowl.png"]

    @pytch.when_green_flag_clicked
    def move_with_keys(self):
        self.go_to_xy(0, -145)

        while True:
            if pytch.key_pressed("a"):
                if self.x_position &gt;= -145:
                    self.change_x(-2)
            if pytch.key_pressed("d"):
                if self.x_position &lt;= 190:
                    self.change_x(2)


class Apple(pytch.Sprite):
    Costumes = ["apple.png"]

    @pytch.when_green_flag_clicked
    def move_down_stage(self):
        self.go_to_xy(100, 200)
        while self.y_position &gt; -140:
            self.change_y(-3)
            if self.touching(Bowl):
                self.hide()
                pytch.broadcast("award-point")


class ScoreKeeper(pytch.Sprite):
    Costumes = ["Dani.png"]

    @pytch.when_green_flag_clicked
    def initialise(self):
        self.go_to_xy(-215, -115)
        self.score = 0
        self.say(self.score)

    @pytch.when_I_receive("award-point")
    def award_point(self):
        self.score += 1
        self.say(self.score)
' data-slug="import-random"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>1</pre></td><td class="linenum"><pre>1</pre></td><td><pre>import pytch</pre></td></tr></tbody><tbody class="diff-add" data-added-text="import random
"><tr><td class="linenum"></td><td class="linenum"><pre>2</pre></td><td><pre>import random</pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>2</pre></td><td class="linenum"><pre>3</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>3</pre></td><td class="linenum"><pre>4</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>4</pre></td><td class="linenum"><pre>5</pre></td><td><pre>class Bowl(pytch.Sprite):</pre></td></tr></tbody></table></div></div><p>(This is how we’ve been using the <code>pytch</code> functions like
<code>pytch.broadcast()</code> already.  When we <code>import</code> Python code like this,
we're doing something very similar to "adding an extension" in Scratch
to make more blocks available.)</p><p>Now we can use the function in the <code>random</code> module which picks a
random whole number.  This is called <code>randint</code> (for <em>random integer</em>).
We need to say what the smallest and largest whole number allowed are.
By trial and error, I worked out:</p><ul>
<li>The smallest (leftmost) <code>x</code>-coordinate which makes sure the apple
  doesn't hit the score-keeper is <code>-145</code>.</li>
<li>The largest (rightmost) <code>x</code>-coordinate which makes sure the apple
  isn't off the right edge of the stage is <code>190</code>.</li>
</ul><p>So these are the values we give to the <code>random.randint</code> function, and
we set a new variable <code>drop_x</code> to the result.  In Scratch, this whole
thing would look like</p><pre><code class="language-scratch">set [drop_x v] to (pick random [-145] to [190])
</code></pre><p>and in Python it looks like this:</p><div class="patch-container" data-code-as-of-commit='import pytch
import random


class Bowl(pytch.Sprite):
    Costumes = ["bowl.png"]

    @pytch.when_green_flag_clicked
    def move_with_keys(self):
        self.go_to_xy(0, -145)

        while True:
            if pytch.key_pressed("a"):
                if self.x_position &gt;= -145:
                    self.change_x(-2)
            if pytch.key_pressed("d"):
                if self.x_position &lt;= 190:
                    self.change_x(2)


class Apple(pytch.Sprite):
    Costumes = ["apple.png"]

    @pytch.when_green_flag_clicked
    def move_down_stage(self):
        drop_x = random.randint(-145, 190)
        self.go_to_xy(100, 200)
        while self.y_position &gt; -140:
            self.change_y(-3)
            if self.touching(Bowl):
                self.hide()
                pytch.broadcast("award-point")


class ScoreKeeper(pytch.Sprite):
    Costumes = ["Dani.png"]

    @pytch.when_green_flag_clicked
    def initialise(self):
        self.go_to_xy(-215, -115)
        self.score = 0
        self.say(self.score)

    @pytch.when_I_receive("award-point")
    def award_point(self):
        self.score += 1
        self.say(self.score)
' data-slug="choose-random-drop-x"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>23</pre></td><td class="linenum"><pre>23</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>24</pre></td><td class="linenum"><pre>24</pre></td><td><pre>    @pytch.when_green_flag_clicked</pre></td></tr><tr><td class="linenum"><pre>25</pre></td><td class="linenum"><pre>25</pre></td><td><pre>    def move_down_stage(self):</pre></td></tr></tbody><tbody class="diff-add" data-added-text="        drop_x = random.randint(-145, 190)
"><tr><td class="linenum"></td><td class="linenum"><pre>26</pre></td><td><pre>        drop_x = random.randint(-145, 190)</pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>26</pre></td><td class="linenum"><pre>27</pre></td><td><pre>        self.go_to_xy(100, 200)</pre></td></tr><tr><td class="linenum"><pre>27</pre></td><td class="linenum"><pre>28</pre></td><td><pre>        while self.y_position &gt; -140:</pre></td></tr><tr><td class="linenum"><pre>28</pre></td><td class="linenum"><pre>29</pre></td><td><pre>            self.change_y(-3)</pre></td></tr></tbody></table></div></div><p>Now we need to use the value of our <code>drop_x</code> variable instead of the
fixed <code>100</code> for the <code>x</code>-coordinate of where the apple falls from:</p><p>We’re changing a line of code here — the blue “<code>?</code>” button will help
explain the “<code>-</code>” and “<code>+</code>” lines.</p><div class="patch-container" data-code-as-of-commit='import pytch
import random


class Bowl(pytch.Sprite):
    Costumes = ["bowl.png"]

    @pytch.when_green_flag_clicked
    def move_with_keys(self):
        self.go_to_xy(0, -145)

        while True:
            if pytch.key_pressed("a"):
                if self.x_position &gt;= -145:
                    self.change_x(-2)
            if pytch.key_pressed("d"):
                if self.x_position &lt;= 190:
                    self.change_x(2)


class Apple(pytch.Sprite):
    Costumes = ["apple.png"]

    @pytch.when_green_flag_clicked
    def move_down_stage(self):
        drop_x = random.randint(-145, 190)
        self.go_to_xy(drop_x, 200)
        while self.y_position &gt; -140:
            self.change_y(-3)
            if self.touching(Bowl):
                self.hide()
                pytch.broadcast("award-point")


class ScoreKeeper(pytch.Sprite):
    Costumes = ["Dani.png"]

    @pytch.when_green_flag_clicked
    def initialise(self):
        self.go_to_xy(-215, -115)
        self.score = 0
        self.say(self.score)

    @pytch.when_I_receive("award-point")
    def award_point(self):
        self.score += 1
        self.say(self.score)
' data-slug="drop-from-random-abscissa"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>24</pre></td><td class="linenum"><pre>24</pre></td><td><pre>    @pytch.when_green_flag_clicked</pre></td></tr><tr><td class="linenum"><pre>25</pre></td><td class="linenum"><pre>25</pre></td><td><pre>    def move_down_stage(self):</pre></td></tr><tr><td class="linenum"><pre>26</pre></td><td class="linenum"><pre>26</pre></td><td><pre>        drop_x = random.randint(-145, 190)</pre></td></tr></tbody><tbody class="diff-del"><tr><td class="linenum"><pre>27</pre></td><td class="linenum"></td><td><pre>        self.go_to_xy(100, 200)</pre></td></tr></tbody><tbody class="diff-add" data-added-text="        self.go_to_xy(drop_x, 200)
"><tr><td class="linenum"></td><td class="linenum"><pre>27</pre></td><td><pre>        self.go_to_xy(drop_x, 200)</pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>28</pre></td><td class="linenum"><pre>28</pre></td><td><pre>        while self.y_position &gt; -140:</pre></td></tr><tr><td class="linenum"><pre>29</pre></td><td class="linenum"><pre>29</pre></td><td><pre>            self.change_y(-3)</pre></td></tr><tr><td class="linenum"><pre>30</pre></td><td class="linenum"><pre>30</pre></td><td><pre>            if self.touching(Bowl):</pre></td></tr></tbody></table></div></div><p>One thing you might notice is that we didn't say <code>self.drop_x</code> here,
we just said <code>drop_x</code>.  By not saying <code>self</code>, Python makes the
<code>drop_x</code> variable only exist inside the <code>move_down_stage</code> method.
Since we won't need <code>drop_x</code> anywhere else, this way avoids cluttering
up our code with variables.</p><p>Now the game is better — each time click the green flag, the
apple falls from a different place.</p></div><div class="chapter-content"><h2>Make apples keep falling</h2><p>We're going to change the game so that the score-keeper is in charge
of making the apple fall from the sky.  We're going to take away the
'hat block' <code>@pytch.when_green_flag_clicked</code> on the Apple's
<code>move_down_stage</code> method, and replace it with a hat block listening
for the broadcast of the message <code>"drop-apple"</code>:</p><div class="patch-container" data-code-as-of-commit='import pytch
import random


class Bowl(pytch.Sprite):
    Costumes = ["bowl.png"]

    @pytch.when_green_flag_clicked
    def move_with_keys(self):
        self.go_to_xy(0, -145)

        while True:
            if pytch.key_pressed("a"):
                if self.x_position &gt;= -145:
                    self.change_x(-2)
            if pytch.key_pressed("d"):
                if self.x_position &lt;= 190:
                    self.change_x(2)


class Apple(pytch.Sprite):
    Costumes = ["apple.png"]

    @pytch.when_I_receive("drop-apple")
    def move_down_stage(self):
        drop_x = random.randint(-145, 190)
        self.go_to_xy(drop_x, 200)
        while self.y_position &gt; -140:
            self.change_y(-3)
            if self.touching(Bowl):
                self.hide()
                pytch.broadcast("award-point")


class ScoreKeeper(pytch.Sprite):
    Costumes = ["Dani.png"]

    @pytch.when_green_flag_clicked
    def initialise(self):
        self.go_to_xy(-215, -115)
        self.score = 0
        self.say(self.score)

    @pytch.when_I_receive("award-point")
    def award_point(self):
        self.score += 1
        self.say(self.score)
' data-slug="launch-apple-on-message-not-green-flag"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>21</pre></td><td class="linenum"><pre>21</pre></td><td><pre>class Apple(pytch.Sprite):</pre></td></tr><tr><td class="linenum"><pre>22</pre></td><td class="linenum"><pre>22</pre></td><td><pre>    Costumes = ["apple.png"]</pre></td></tr><tr><td class="linenum"><pre>23</pre></td><td class="linenum"><pre>23</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-del"><tr><td class="linenum"><pre>24</pre></td><td class="linenum"></td><td><pre>    @pytch.when_green_flag_clicked</pre></td></tr></tbody><tbody class="diff-add" data-added-text='    @pytch.when_I_receive("drop-apple")
'><tr><td class="linenum"></td><td class="linenum"><pre>24</pre></td><td><pre>    @pytch.when_I_receive("drop-apple")</pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>25</pre></td><td class="linenum"><pre>25</pre></td><td><pre>    def move_down_stage(self):</pre></td></tr><tr><td class="linenum"><pre>26</pre></td><td class="linenum"><pre>26</pre></td><td><pre>        drop_x = random.randint(-145, 190)</pre></td></tr><tr><td class="linenum"><pre>27</pre></td><td class="linenum"><pre>27</pre></td><td><pre>        self.go_to_xy(drop_x, 200)</pre></td></tr></tbody></table></div></div><p>Right now, the game won't work, because nothing is broadcasting the
<code>"drop-apple"</code> message.  We'll give that job to the score-keeper
now.</p><p>We'll make a new method in the ScoreKeeper sprite which will keep
dropping apples.  A good name for this is <code>drop_apples</code>, so we
start defining that method:</p><div class="patch-container" data-code-as-of-commit='import pytch
import random


class Bowl(pytch.Sprite):
    Costumes = ["bowl.png"]

    @pytch.when_green_flag_clicked
    def move_with_keys(self):
        self.go_to_xy(0, -145)

        while True:
            if pytch.key_pressed("a"):
                if self.x_position &gt;= -145:
                    self.change_x(-2)
            if pytch.key_pressed("d"):
                if self.x_position &lt;= 190:
                    self.change_x(2)


class Apple(pytch.Sprite):
    Costumes = ["apple.png"]

    @pytch.when_I_receive("drop-apple")
    def move_down_stage(self):
        drop_x = random.randint(-145, 190)
        self.go_to_xy(drop_x, 200)
        while self.y_position &gt; -140:
            self.change_y(-3)
            if self.touching(Bowl):
                self.hide()
                pytch.broadcast("award-point")


class ScoreKeeper(pytch.Sprite):
    Costumes = ["Dani.png"]

    @pytch.when_green_flag_clicked
    def initialise(self):
        self.go_to_xy(-215, -115)
        self.score = 0
        self.say(self.score)

    @pytch.when_I_receive("award-point")
    def award_point(self):
        self.score += 1
        self.say(self.score)

    def drop_apples(self):
' data-slug="define-launch-apples-method"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>45</pre></td><td class="linenum"><pre>45</pre></td><td><pre>    def award_point(self):</pre></td></tr><tr><td class="linenum"><pre>46</pre></td><td class="linenum"><pre>46</pre></td><td><pre>        self.score += 1</pre></td></tr><tr><td class="linenum"><pre>47</pre></td><td class="linenum"><pre>47</pre></td><td><pre>        self.say(self.score)</pre></td></tr></tbody><tbody class="diff-add" data-added-text="
    def drop_apples(self):
"><tr><td class="linenum"></td><td class="linenum"><pre>48</pre></td><td><pre></pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>49</pre></td><td><pre>    def drop_apples(self):</pre></td></tr></tbody></table></div></div><p>We want to keep making apples drop from the top of the stage forever.
Just like in the code which lets the player move the bowl, we do this
with a <code>while True:</code> loop in Python.  Inside that loop, we want to
keep broadcasting <code>"drop-apple"</code>.  But here, we will use the
<code>broadcast_and_wait</code> function, because we don't want to drop the next
Apple until the current one has either been caught or reached the
bottom of the stage.  In Scratch, the code would be</p><pre><code class="language-scratch">forever
broadcast (drop-apple v) and wait
</code></pre><p>and in Pytch it's</p><div class="patch-container" data-code-as-of-commit='import pytch
import random


class Bowl(pytch.Sprite):
    Costumes = ["bowl.png"]

    @pytch.when_green_flag_clicked
    def move_with_keys(self):
        self.go_to_xy(0, -145)

        while True:
            if pytch.key_pressed("a"):
                if self.x_position &gt;= -145:
                    self.change_x(-2)
            if pytch.key_pressed("d"):
                if self.x_position &lt;= 190:
                    self.change_x(2)


class Apple(pytch.Sprite):
    Costumes = ["apple.png"]

    @pytch.when_I_receive("drop-apple")
    def move_down_stage(self):
        drop_x = random.randint(-145, 190)
        self.go_to_xy(drop_x, 200)
        while self.y_position &gt; -140:
            self.change_y(-3)
            if self.touching(Bowl):
                self.hide()
                pytch.broadcast("award-point")


class ScoreKeeper(pytch.Sprite):
    Costumes = ["Dani.png"]

    @pytch.when_green_flag_clicked
    def initialise(self):
        self.go_to_xy(-215, -115)
        self.score = 0
        self.say(self.score)

    @pytch.when_I_receive("award-point")
    def award_point(self):
        self.score += 1
        self.say(self.score)

    def drop_apples(self):
        while True:
            pytch.broadcast_and_wait("drop-apple")
' data-slug="bcast/wait-launch-apples-in-loop"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>47</pre></td><td class="linenum"><pre>47</pre></td><td><pre>        self.say(self.score)</pre></td></tr><tr><td class="linenum"><pre>48</pre></td><td class="linenum"><pre>48</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>49</pre></td><td class="linenum"><pre>49</pre></td><td><pre>    def drop_apples(self):</pre></td></tr></tbody><tbody class="diff-add" data-added-text='        while True:
            pytch.broadcast_and_wait("drop-apple")
'><tr><td class="linenum"></td><td class="linenum"><pre>50</pre></td><td><pre>        while True:</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>51</pre></td><td><pre>            pytch.broadcast_and_wait("drop-apple")</pre></td></tr></tbody></table></div></div><p>Finally, we need to say that we want this to start happening when the
green flag is clicked:</p><div class="patch-container" data-code-as-of-commit='import pytch
import random


class Bowl(pytch.Sprite):
    Costumes = ["bowl.png"]

    @pytch.when_green_flag_clicked
    def move_with_keys(self):
        self.go_to_xy(0, -145)

        while True:
            if pytch.key_pressed("a"):
                if self.x_position &gt;= -145:
                    self.change_x(-2)
            if pytch.key_pressed("d"):
                if self.x_position &lt;= 190:
                    self.change_x(2)


class Apple(pytch.Sprite):
    Costumes = ["apple.png"]

    @pytch.when_I_receive("drop-apple")
    def move_down_stage(self):
        drop_x = random.randint(-145, 190)
        self.go_to_xy(drop_x, 200)
        while self.y_position &gt; -140:
            self.change_y(-3)
            if self.touching(Bowl):
                self.hide()
                pytch.broadcast("award-point")


class ScoreKeeper(pytch.Sprite):
    Costumes = ["Dani.png"]

    @pytch.when_green_flag_clicked
    def initialise(self):
        self.go_to_xy(-215, -115)
        self.score = 0
        self.say(self.score)

    @pytch.when_I_receive("award-point")
    def award_point(self):
        self.score += 1
        self.say(self.score)

    @pytch.when_green_flag_clicked
    def drop_apples(self):
        while True:
            pytch.broadcast_and_wait("drop-apple")
' data-slug="start-launching-apples-on-green-flag"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>46</pre></td><td class="linenum"><pre>46</pre></td><td><pre>        self.score += 1</pre></td></tr><tr><td class="linenum"><pre>47</pre></td><td class="linenum"><pre>47</pre></td><td><pre>        self.say(self.score)</pre></td></tr><tr><td class="linenum"><pre>48</pre></td><td class="linenum"><pre>48</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-add" data-added-text="    @pytch.when_green_flag_clicked
"><tr><td class="linenum"></td><td class="linenum"><pre>49</pre></td><td><pre>    @pytch.when_green_flag_clicked</pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>49</pre></td><td class="linenum"><pre>50</pre></td><td><pre>    def drop_apples(self):</pre></td></tr><tr><td class="linenum"><pre>50</pre></td><td class="linenum"><pre>51</pre></td><td><pre>        while True:</pre></td></tr><tr><td class="linenum"><pre>51</pre></td><td class="linenum"><pre>52</pre></td><td><pre>            pytch.broadcast_and_wait("drop-apple")</pre></td></tr></tbody></table></div></div><p>If you try the game now, it doesn't work!  What's happening is that
we've told the Apple to <code>hide</code> itself when it's caught, but we haven't
told it to <code>show</code> itself when it starts dropping.  We can fix that:</p><div class="patch-container" data-code-as-of-commit='import pytch
import random


class Bowl(pytch.Sprite):
    Costumes = ["bowl.png"]

    @pytch.when_green_flag_clicked
    def move_with_keys(self):
        self.go_to_xy(0, -145)

        while True:
            if pytch.key_pressed("a"):
                if self.x_position &gt;= -145:
                    self.change_x(-2)
            if pytch.key_pressed("d"):
                if self.x_position &lt;= 190:
                    self.change_x(2)


class Apple(pytch.Sprite):
    Costumes = ["apple.png"]

    @pytch.when_I_receive("drop-apple")
    def move_down_stage(self):
        drop_x = random.randint(-145, 190)
        self.go_to_xy(drop_x, 200)
        self.show()
        while self.y_position &gt; -140:
            self.change_y(-3)
            if self.touching(Bowl):
                self.hide()
                pytch.broadcast("award-point")


class ScoreKeeper(pytch.Sprite):
    Costumes = ["Dani.png"]

    @pytch.when_green_flag_clicked
    def initialise(self):
        self.go_to_xy(-215, -115)
        self.score = 0
        self.say(self.score)

    @pytch.when_I_receive("award-point")
    def award_point(self):
        self.score += 1
        self.say(self.score)

    @pytch.when_green_flag_clicked
    def drop_apples(self):
        while True:
            pytch.broadcast_and_wait("drop-apple")
' data-slug="show-apple-when-fall-starts"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>25</pre></td><td class="linenum"><pre>25</pre></td><td><pre>    def move_down_stage(self):</pre></td></tr><tr><td class="linenum"><pre>26</pre></td><td class="linenum"><pre>26</pre></td><td><pre>        drop_x = random.randint(-145, 190)</pre></td></tr><tr><td class="linenum"><pre>27</pre></td><td class="linenum"><pre>27</pre></td><td><pre>        self.go_to_xy(drop_x, 200)</pre></td></tr></tbody><tbody class="diff-add" data-added-text="        self.show()
"><tr><td class="linenum"></td><td class="linenum"><pre>28</pre></td><td><pre>        self.show()</pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>28</pre></td><td class="linenum"><pre>29</pre></td><td><pre>        while self.y_position &gt; -140:</pre></td></tr><tr><td class="linenum"><pre>29</pre></td><td class="linenum"><pre>30</pre></td><td><pre>            self.change_y(-3)</pre></td></tr><tr><td class="linenum"><pre>30</pre></td><td class="linenum"><pre>31</pre></td><td><pre>            if self.touching(Bowl):</pre></td></tr></tbody></table></div></div><p>and this is now a playable game written in Python — congratulations!</p></div><div class="chapter-content"><h2>Improve the game</h2><p>Here are some ideas on how you could make this game more fun:</p><ul>
<li>
<p>Add a pause between one apple being caught / missed and the next one
  appearing.  Use the help sidebar to find the Pytch version of
  Scratch’s <code>wait () seconds</code> block.  (Hint: just after doing
  <code>pytch.broadcast_and_wait("drop-apple")</code> is a good place to pause.)</p>
</li>
<li>
<p>The <code>x</code>-coordinate where the apple starts is already random.  Make
  the starting <code>y</code>-coordinate be random too.  If an apple starts lower
  down the stage, the player has less time to get the bowl under the
  apple, making the game more challenging.</p>
</li>
<li>
<p>Play a sound when the player catches an apple.  There is an
  apple-crunching sound as part of this tutorial.  Make this sound
  part of the <code>Apple</code> sprite, by setting a <code>Sounds</code> variable just
  under the <code>Costumes</code> variable: <code>Sounds = ["apple-crunch.wav"]</code>.  Use
  the slide-out help panel to find the Pytch function for playing the
  sound.</p>
</li>
<li>
<p>Change how quickly the player can move the bowl.  A bit quicker
  would make the game easier; a bit slower would make the game harder.
  The speed appears in two places: for moving left and for moving
  right.  Investigate whether it’s worth setting a variable to hold
  the speed.  A variable makes it easier to experiment with the
  player's speed, but it is a bit more work to write the code in the
  first place.</p>
</li>
<li>
<p>Add the provided <code>orange.png</code> costume to the Apple.  Its <code>Costumes</code>
  list will then have two things in it.  (Your code will be clearer if
  you also change the name of the sprite to <code>Fruit</code>!)  Each time the
  <code>Fruit</code> appears, choose randomly which costume to wear.  (Hint: a
  good place for this code is in the first part of the
  <code>move_down_stage()</code> method, before the <code>while</code> loop.)  The slide-out
  help panel will tell you the Pytch version of Scratch’s <code>switch
  costume</code> block.</p>
</li>
<li>
<p>Make the referee jump up and down in celebration when the player
  catches an apple.  In Scratch you might use the <code>repeat</code> block.  Use
  the slide-out help panel to find how to do this in Pytch.</p>
</li>
<li>
<p>Make there be a fixed number of apples — maybe 8.  Advanced: At the
  end of the game, make the referee say something like "You got 5 out
  of 8".  You can use "f-strings" (<a href="https://docs.python.org/3/tutorial/inputoutput.html#tut-f-strings">read about them in the Python
  documentation</a>)
  to get the scorekeeper to say this.</p>
</li>
</ul></div><div class="chapter-content"><h2>Credits</h2><p>We have used various freely-available resources to make this project:</p><div class="asset-credits"><p class="credit-intro">For <code class="asset-filename">Dani.png</code>, <code class="asset-filename">apple.png</code>, <code class="asset-filename">bowl.png</code>, <code class="asset-filename">orange.png</code> (used in the project):</p><div class="credits"><p>The apple, orange, bowl, and Dani images are copyright the Lifelong
Kindergarten Group at MIT Media Lab, and are part of Scratch.  We use
them under the terms of the <a href="https://creativecommons.org/licenses/by-sa/2.0/">Creative Commons Attribution-ShareAlike
2.0</a> licence.  We
have re-rendered the originals at a size suitable for our project.</p><p>Scratch is developed by the Lifelong Kindergarten Group at the MIT
Media Lab.  See <a href="https://scratch.mit.edu/">https://scratch.mit.edu/</a>.</p></div><p class="credit-intro">For <code class="asset-filename">apple-crunch.wav</code> (used in the project):</p><div class="credits"><p>The <a href="https://freesound.org/people/Koops/sounds/20265/">sound of a crunching
apple</a> is copyright
Freesound user "Koops".  We use it under the terms of the <a href="https://creativecommons.org/licenses/by/3.0/">Creative
Commons Attribution 3.0</a>
licence.</p></div><p class="credit-intro">For <code class="asset-filename">screenshot-w240-darker-bg.png</code>, <code class="asset-filename">screenshot-w240.png</code> (used in the tutorial text/summary):</p><div class="credits"><p>The screenshot files were screengrabbed by the Pytch team.  To the
extent that they are based on material from Scratch, we use them under
the terms of the <a href="https://creativecommons.org/licenses/by-sa/2.0/">Creative Commons Attribution-ShareAlike
2.0</a> licence.</p><p>Scratch is developed by the Lifelong Kindergarten Group at the MIT
Media Lab.  See <a href="https://scratch.mit.edu/">https://scratch.mit.edu/</a>.</p></div></div></div></div>